/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufrgs.inf.prav.interop;

import java.io.FileInputStream;
import java.util.Properties;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

/**
 *
 * @author Fernando
 */
public class AppConfig {

    private static AppConfig uniqueInstance = new AppConfig();

    //properties
    private String streamingServerIP;


    public AppConfig(){
        loadConfigsFromURL();
    }
    
    private void loadConfigsFromURL(){
        ExternalContext ec = FacesContext.getCurrentInstance().
                getExternalContext();
        ServletContext context = (ServletContext)ec.getContext();
        String propsFileName = context.getRealPath("/WEB-INF/obai-config.properties");
        Properties props = new Properties();
        try {
            props.load(new FileInputStream(propsFileName));
        } catch (Exception e) {
            System.out.println("Cannot load properties file");
        }
        streamingServerIP = props.getProperty("streamingserver.address");
        System.out.println("streamingserver.address: " + streamingServerIP);
    }

    public static AppConfig getInstance() {
        if (uniqueInstance == null)
            uniqueInstance = new AppConfig();
        return uniqueInstance;
    }


    // <editor-fold defaultstate="collapsed" desc="Getters and Setters">
    public String getStreamingServerIP() {
        return streamingServerIP;
    }

    public void setStreamingServerIP(String streamingServerIP) {
        this.streamingServerIP = streamingServerIP;
    }
    // </editor-fold>

}
